package com.housediyadmin.service
{   	
	import com.housediyadmin.events.picModelEvent.AddPicturesEvent;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.messaging.ChannelSet;
	import mx.messaging.channels.AMFChannel;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.RemoteObject;
	
	import org.robotlegs.mvcs.Actor;
	
	
	/**
	 * 
	 * @author yanghanbing
	 * 2011/03/09
	 */ 
	public class PictureRemoteObjectService extends Actor
	{
		public var picRemoteObject:RemoteObject;
		
		public function PictureRemoteObjectService()
		{
			super();
			
			var amfChannel:Array = [new AMFChannel(null, "http://localhost/housediyadmin/Gateway.aspx")];
			//var amfChannel:Array = [new AMFChannel(null, "http://10.60.1.120/HouseDiyAdmin/Gateway.aspx")];
			var channelSet:ChannelSet = new ChannelSet();
			channelSet.channels = amfChannel;
			
			picRemoteObject = new RemoteObject("fluorine");
			picRemoteObject.source = "HouseDiyService.HouseDiyAction";
			picRemoteObject.showBusyCursor = true;
			picRemoteObject.channelSet = channelSet;
			
			picRemoteObject.getOperation("addPicture").addEventListener(ResultEvent.RESULT, addPictureResultHandler);
			picRemoteObject.getOperation("addPicture").addEventListener(FaultEvent.FAULT, faultHandler);
		}
		public function addPictures(picArray:ArrayCollection):void
		{
			picRemoteObject.addPicture(picArray);
		}
		
		private function addPictureResultHandler(event:ResultEvent):void
		{
			dispatch(new AddPicturesEvent(AddPicturesEvent.UPDATE_PICTURE_MODEL, event.result as ArrayCollection));
		}
		
		private function faultHandler(event:FaultEvent):void
		{
			Alert.show(" fault :" + event.toString());
		}
	}
}